// global variable that points to the site's url

function showLoadingStatus(divName){
	$(divName).attr("innerHTML","<img src='" + siteUrl + "system/application/views/" + skinDir + "/images/indicator.gif' /> loading") 	

}

function removeLoadingStatus(divName){
	$(divName).attr("innerHTML","");
}

// when everything loads do:
$(document).ready(function() {

	
	$('#login_form').hide();
	$('#map_login').click(function() {
		
		$('#login_form').toggle("normal");
		
	});
	
	$('#registration_form').hide()
    var logInOptions = { 
        // target:        '#logInStatus',   // target element(s) to be updated with server response 
        beforeSubmit:  logInRequest,  // pre-submit callback 
        success:       logInResponse,  // post-submit callback 
 
        // other available options: 
        url:       siteUrl + "ajaxcontroller/login",         // override for form's 'action' attribute 
        type:      'post',        // 'get' or 'post', override for form's 'method' attribute 
        dataType:  'xml'       // 'xml', 'script', or 'json' (expected server response type) 
        // clearForm: true,        // clear all form fields after successful submit 
        // resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 
 
    // bind form using 'ajaxForm' 
    $('#logInForm').ajaxForm(logInOptions); 
    

	
	// switch from registration dialog to login dialog
	$('#showLogInDialog').click(function() {
		$('#registrationDialog').hide("slow", function() { $('#logInDialog').show("slow"); });
		
		
	});
})

// here are the helper function

function logInRequest(formData, jqForm, options) { 
	showLoadingStatus("#logInStatus");
	var queryString = $.param(formData); 
    return true; 
} 
 
function logInResponse(responseText, statusText)  { 
    status = $('status',responseText).text();
    message = $('message', responseText).text();
    
	if (status == 1){
		$("#logInDialog").hide("slow", function(){ window.location = siteUrl + "admin/controlPanel";});
	} 
	$("#logInStatus").attr("innerHTML",message)
		$("#logInStatus").addClass("highlight")
} 



